//
//  YZMainTabBar.m
//  VET
//
//  Created by Lam BG on 2018/6/25.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZMainTabBar.h"

#import "TBCityIconFont.h"
#include "YZStatementHeader.h"

#import "UIView+Frame.h"
#import "UIColor+Category.h"

@implementation YZMainTabBar

- (instancetype)init {
    
    if (self = [super init]) {

//        self.translucent = NO; // 明显分割
        
        // 添加中间的按钮
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\ue63a", 40, yzGreenColor)] forState:UIControlStateNormal];
        btn.bounds = CGRectMake(0, 0, 40, 40);
        
        [self addSubview:btn];
        self.centerBtn = btn;
    }
    
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    int index = 0;
    CGFloat wigth = self.bounds.size.width / 5;
    for (UIView* sub in self.subviews) {
        if ([sub isKindOfClass:NSClassFromString(@"UITabBarButton")]) {

            sub.left = index * wigth;
            sub.width = wigth;

            index++;
            // 当下标是第三个的时候
            if (index == 2) {

                // 直接加 给中间留空
                index++;
            }
        }
    }

    // 调整中间按钮的位置
    self.centerBtn.center = CGPointMake(self.bounds.size.width * 0.5, 49.0 * 0.5);
}

// 按钮是添加进去的 如果超出视图高度会收不到响应
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    if (self.isHidden == NO) {

        CGPoint newPoint = [self convertPoint:point toView:self.centerBtn];
        if ( [self.centerBtn pointInside:newPoint withEvent:event]) {

            return self.centerBtn;
        } else {

            return [super hitTest:point withEvent:event];
        }

    } else {

        return [super hitTest:point withEvent:event];
    }
}

@end
